import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createStyleImportPlugin } from 'vite-plugin-style-import'
import postCssPxToRem from "postcss-pxtorem"
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(),
   createStyleImportPlugin({
      resolves: [{
          libraryName: '@nutui/nutui',
          libraryNameChangeCase: 'pascalCase',
          resolveStyle: (name) => {
            return `@nutui/nutui/dist/packages/${name.toLowerCase()}/index.scss`
          },
      }]
    })],
  server: {             
    host: '0.0.0.0',
    hmr:true
  },
  resolve:{
    //设置路径别名
    alias: {
      "@": path.resolve("./src"), // @代替src
      },
  },
  //scss颜色配置
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/assets/css/common.scss";@import "@nutui/nutui/dist/styles/variables.scss";`
      }
    },
    postcss: {
      plugins: [
        // 自适应的配置
        postCssPxToRem({
          rootValue: 75, // 设计稿宽度除以 10，  开头大写的Px 不转换 => height: 100Px, 内联样式不转换，需要 / 75 转成 rem
          unitPrecision: 6, // 计算结果保留 6 位小数
          propList: ['*'], // 可以从px更改为rem的属性  感叹号开头的不转换
          replace: true, // 转换成 rem 以后，不保留原来的 px 单位属性
        })
      ]
    }
  }
})
